/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package project;

import java.sql.Connection;
import java.sql.Date;
/**
 *
 * @author jon
 */import java.sql.DriverManager;

import java.sql.PreparedStatement;
import java.sql.SQLException;
public class Branch {
    private int branch_number;
    private int address_zipcode;
    private String address_state;
    private String address_city;
    private String address_street;
    private String telephon_number;
    private String fax_number;
    private String manager_name;
    private Date manager_timestarted;
    private double manager_bonus;

    // This and all constructors were generated by netbeans
    public Branch(int branch_number, int address_zipcode, String address_state, String address_city,
            String address_street, String telephon_number, String fax_number, String manager_name,
            Date manager_timestarted, double manager_bonus) {
        this.branch_number = 0;
        this.address_zipcode = address_zipcode;
        this.address_state = address_state;
        this.address_city = address_city;
        this.address_street = address_street;
        this.telephon_number = telephon_number;
        this.fax_number = fax_number;
        this.manager_name = manager_name;
        this.manager_timestarted = manager_timestarted;
        this.manager_bonus = manager_bonus;
    }

    // This and all getters/setters were generated by netbeans
    /**
     * @return the branch_number
     */
    public int getBranch_number() {
        return branch_number;
    }

    /**
     * @param branch_number the branch_number to set
     */
    public void setBranch_number(int branch_number) {
        this.branch_number = branch_number;
    }

    /**
     * @return the address_zipcode
     */
    public int getAddress_zipcode() {
        return address_zipcode;
    }

    /**
     * @param address_zipcode the address_zipcode to set
     */
    public void setAddress_zipcode(int address_zipcode) {
        this.address_zipcode = address_zipcode;
    }

    /**
     * @return the address_state
     */
    public String getAddress_state() {
        return address_state;
    }

    /**
     * @param address_state the address_state to set
     */
    public void setAddress_state(String address_state) {
        this.address_state = address_state;
    }

    /**
     * @return the address_city
     */
    public String getAddress_city() {
        return address_city;
    }

    /**
     * @param address_city the address_city to set
     */
    public void setAddress_city(String address_city) {
        this.address_city = address_city;
    }

    /**
     * @return the address_street
     */
    public String getAddress_street() {
        return address_street;
    }

    /**
     * @param address_street the address_street to set
     */
    public void setAddress_street(String address_street) {
        this.address_street = address_street;
    }

    /**
     * @return the telephon_number
     */
    public String getTelephon_number() {
        return telephon_number;
    }

    /**
     * @param telephon_number the telephon_number to set
     */
    public void setTelephon_number(String telephon_number) {
        this.telephon_number = telephon_number;
    }

    /**
     * @return the fax_number
     */
    public String getFax_number() {
        return fax_number;
    }

    /**
     * @param fax_number the fax_number to set
     */
    public void setFax_number(String fax_number) {
        this.fax_number = fax_number;
    }

    /**
     * @return the manager_name
     */
    public String getManager_name() {
        return manager_name;
    }

    /**
     * @param manager_name the manager_name to set
     */
    public void setManager_name(String manager_name) {
        this.manager_name = manager_name;
    }

    /**
     * @return the manager_timestarted
     */
    public Date getManager_timestarted() {
        return manager_timestarted;
    }

    /**
     * @param manager_timestarted the manager_timestarted to set
     */
    public void setManager_timestarted(Date manager_timestarted) {
        this.manager_timestarted = manager_timestarted;
    }

    /**
     * @return the manager_bonus
     */
    public double getManager_bonus() {
        return manager_bonus;
    }

    /**
     * @param manager_bonus the manager_bonus to set
     */
    public void setManager_bonus(double manager_bonus) {
        this.manager_bonus = manager_bonus;
    }

    public void insert()
    {
        try
        {
            String host = "jdbc:oracle:thin:@localhost:1521:xe";
            String username = "jon";
            String password = "chaosecco";
            String driverName = "oracle.jdbc.driver.OracleDriver";
            Class.forName(driverName);

            Connection connection = DriverManager.getConnection(host,
                    username, password);
            System.out.print("Connected successfully.");
            String insertQuery = "INSERT INTO BRANCH(" +
                    "branch_number, " +
                    "branch_address_zipcode, " +
                    "branch_address_state, " +
                    "branch_address_city, " +
                    "branch_address_street, " +
                    "telephone_number, "  +
                    "fax_number, " + 
                    "manager_name, " +
                    "manager_time_started, " +
                    "manager_bonus)" +
                    "VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
            PreparedStatement ps = connection.prepareStatement(insertQuery);
            ps.setInt(1, branch_number);
            ps.setInt(2, address_zipcode);
            ps.setString(3, address_state);
            ps.setString(4, address_city);
            ps.setString(5, address_street);
            ps.setString(6, telephon_number);
            ps.setString(7, fax_number);
            ps.setString(8, manager_name);
            ps.setDate(9, manager_timestarted);
            ps.setDouble(10, manager_bonus);
            System.out.println("Before execute update");
            ps.executeUpdate();
            
            connection.close();
        }

        catch (SQLException e)
        {
            System.out.println("ERROR: " + e.getMessage());
        }

        catch(ClassNotFoundException e)
        {
            System.out.println("ERROR: " + e.getMessage());
        }
    }
}
